#pragma once

#include <functional>
#include <string>

class Reactor;

using handler_t = std::function<std::string(std::string&)>;

class Connection            // 基类，描述连接对象的基本函数
{
public:

    Connection()
        :_events(0)
        ,_owner(nullptr)
    {
        ;
    }

    void setEvent(uint32_t events)
    {
        _events = events;
    }

    uint32_t getEvent()
    {
        return _events;
    }

    void setOwner(Reactor* owner)
    {
        _owner = owner;
    }

    Reactor* getOwner()
    {
        return _owner;
    }

    void registerHandler(handler_t handler)
    {
        _handler = handler;
    }

    virtual void recver() = 0;
    virtual void sender() = 0;
    virtual void excepter() = 0;
    virtual int getSockfd() = 0;

    ~Connection()
    {
        ;
    }
    
protected:

    uint32_t _events;           // 关心的事件
    Reactor* _owner;            // 回指指针
    handler_t _handler;         // 回调函数
};